from django.db import models
from rest_framework import serializers


# Create your models here.
class User(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=100, unique=True, verbose_name="用户名")
    password = models.CharField(max_length=100, verbose_name="密码")
    avatar = models.CharField(max_length=255, null=True, verbose_name="用户头像")
    email = models.CharField(max_length=100, null=True, verbose_name="用户邮箱")
    phonenumber = models.CharField(max_length=11, null=True, verbose_name="手机号码")
    login_date = models.DateField(null=True, verbose_name="最后登录时间")
    status = models.IntegerField(null=True, verbose_name="帐号状态（0正常 1停用）")
    create_time = models.DateField(null=True, verbose_name="创建时间", )
    update_time = models.DateField(null=True, verbose_name="更新时间")
    remark = models.CharField(max_length=500, null=True, verbose_name="备注")

    class Meta:
        db_table = 'user'

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class Stock_K(models.Model):
    id = models.AutoField(primary_key=True)
    code = models.CharField(max_length=100, unique=True, verbose_name="股票代码")
    date = models.CharField(max_length=100, verbose_name="日期")
    open = models.FloatField(max_length=100, verbose_name="开盘价")
    close = models.FloatField(max_length=100, verbose_name="收盘价")
    high = models.FloatField(max_length=100, verbose_name="最高价")
    low = models.FloatField(max_length=100, verbose_name="最低价")

    class Meta:
        db_table = 'stock_k'

class Stock_KSerializer(serializers.ModelSerializer):
    class Meta:
        model = Stock_K
        fields = ['code', 'date', 'open', 'close', 'high', 'low']


class Stock_NLP(models.Model):
    id = models.AutoField(primary_key=True)
    stock_code = models.CharField(max_length=100, unique=True, verbose_name="股票代码")
    stock_name = models.CharField(max_length=100, verbose_name="股票名称")
    data = models.CharField(max_length=100, verbose_name="评论")
    emo = models.CharField(max_length=100,verbose_name="情感")

    class Meta:
        db_table = 'stock_nlp'

class Stock_NLPSerializer(serializers.ModelSerializer):
    class Meta:
        model = Stock_NLP
        fields = ['stock_code', 'stock_name', 'data','emo']


